# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[return dev.get_name() == dev_name
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752e4c>}
nname: 0
n 0(None)[return dev.get_name() == dev_name
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752dcc>}
nname: 69
n 69(None)[return d[0]
]:
	i: 48(), 68()
	o: 

nname: 68
n 68(None)[]:
	i: 0(f)
	o: 69()

nname: 48
n 48(None)[raise NameError('No such interface (%s)' % dev_name)
]:
	i: 0(t)
	o: 69()

nname: 0
n 0(d == [])[devs = NM.get_devices()
d = filter((lambda dev: dev.get_name() == dev_name), devs)
]:
	i: 
	o: 48(t), 68(f)

nname: 0
n 0(None)[devs = NM.get_devices()
d = filter((lambda dev: dev.get_name() == dev_name), devs)
if d == []:
	raise NameError('No such interface (%s)' % dev_name)
return d[0]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb775252c>}
nname: 0
n 0(None)[return net.get_name() == essid
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752f4c>}
nname: 0
n 0(None)[return net.get_name() == essid
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752e8c>}
nname: 69
n 69(None)[return n[0]
]:
	i: 48(), 68()
	o: 

nname: 68
n 68(None)[]:
	i: 0(f)
	o: 69()

nname: 48
n 48(None)[raise NameError('No such ESSID (%s)' % net_name)
]:
	i: 0(t)
	o: 69()

nname: 0
n 0(n == [])[nets = dev.get_networks()
n = filter((lambda net: net.get_name() == essid), nets)
]:
	i: 
	o: 48(t), 68(f)

nname: 0
n 0(None)[nets = dev.get_networks()
n = filter((lambda net: net.get_name() == essid), nets)
if n == []:
	raise NameError('No such ESSID (%s)' % net_name)
return n[0]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb775286c>}
nname: 119
n 119(None)[print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 0(AL), 118()
	o: 

nname: 118
n 118(None)[]:
	i: 30(AF), 37()
	o: 119()

nname: 37
n 37(None)[for dev in devs:
name = dev.get_name()
ip = dev.get_ip_address()
type = dev.get_type()
active = dev.get_link_active()
print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
]:
	i: 30(for)
	o: 118()

nname: 30
n 30(None)[]:
	i: 0(loop)
	o: 37(for), 118(AF)

nname: 0
n 0(None)[devs = NM.get_devices()
print '+--------+----------+--------+---------------+---------------+---------------+'
print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 
	o: 30(loop), 119(AL)

nname: 119
n 119(None)[print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 37()
	o: 

nname: 37
n 37(None)[for dev in devs:
	name = dev.get_name()
	ip = dev.get_ip_address()
	type = dev.get_type()
	active = dev.get_link_active()
	print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
]:
	i: 0(for)
	o: 119()

nname: 0
n 0(None)[devs = NM.get_devices()
print '+--------+----------+--------+---------------+---------------+---------------+'
print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 
	o: 37(for)

nname: 119
n 119(None)[print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 0()
	o: 

nname: 0
n 0(None)[devs = NM.get_devices()
print '+--------+----------+--------+---------------+---------------+---------------+'
print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
print '+--------+----------+--------+---------------+---------------+---------------+'
for dev in devs:
	name = dev.get_name()
	ip = dev.get_ip_address()
	type = dev.get_type()
	active = dev.get_link_active()
	print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
]:
	i: 
	o: 119()

nname: 0
n 0(None)[devs = NM.get_devices()
print '+--------+----------+--------+---------------+---------------+---------------+'
print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
print '+--------+----------+--------+---------------+---------------+---------------+'
for dev in devs:
	name = dev.get_name()
	ip = dev.get_ip_address()
	type = dev.get_type()
	active = dev.get_link_active()
	print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
print '+--------+----------+--------+---------------+---------------+---------------+'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752f4c>}
nname: 151
n 151(None)[print '+----------------+--------+--------+--------+'
]:
	i: 0(AL), 150()
	o: 

nname: 150
n 150(None)[]:
	i: 64(AF), 71()
	o: 151()

nname: 71
n 71(None)[for net in networks:
net_name = net.get_name()
net_strength = net.get_strength()
net_rate = net.get_rate() >> 10
net_encrypted = net.get_encrypted()
print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
]:
	i: 64(for)
	o: 150()

nname: 64
n 64(None)[]:
	i: 0(loop)
	o: 71(for), 150(AF)

nname: 0
n 0(None)[args = parameter_s.split()
dev_name = args[0]
dev = _get_device_by_name(dev_name)
networks = dev.get_networks()
print '+----------------+--------+--------+--------+'
print '| ESSID          |Strength|  Rate  | Crypt. |'
print '+----------------+--------+--------+--------+'
]:
	i: 
	o: 64(loop), 151(AL)

nname: 151
n 151(None)[print '+----------------+--------+--------+--------+'
]:
	i: 71()
	o: 

nname: 71
n 71(None)[for net in networks:
	net_name = net.get_name()
	net_strength = net.get_strength()
	net_rate = net.get_rate() >> 10
	net_encrypted = net.get_encrypted()
	print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
]:
	i: 0(for)
	o: 151()

nname: 0
n 0(None)[args = parameter_s.split()
dev_name = args[0]
dev = _get_device_by_name(dev_name)
networks = dev.get_networks()
print '+----------------+--------+--------+--------+'
print '| ESSID          |Strength|  Rate  | Crypt. |'
print '+----------------+--------+--------+--------+'
]:
	i: 
	o: 71(for)

nname: 151
n 151(None)[print '+----------------+--------+--------+--------+'
]:
	i: 0()
	o: 

nname: 0
n 0(None)[args = parameter_s.split()
dev_name = args[0]
dev = _get_device_by_name(dev_name)
networks = dev.get_networks()
print '+----------------+--------+--------+--------+'
print '| ESSID          |Strength|  Rate  | Crypt. |'
print '+----------------+--------+--------+--------+'
for net in networks:
	net_name = net.get_name()
	net_strength = net.get_strength()
	net_rate = net.get_rate() >> 10
	net_encrypted = net.get_encrypted()
	print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
]:
	i: 
	o: 151()

nname: 0
n 0(None)[args = parameter_s.split()
dev_name = args[0]
dev = _get_device_by_name(dev_name)
networks = dev.get_networks()
print '+----------------+--------+--------+--------+'
print '| ESSID          |Strength|  Rate  | Crypt. |'
print '+----------------+--------+--------+--------+'
for net in networks:
	net_name = net.get_name()
	net_strength = net.get_strength()
	net_rate = net.get_rate() >> 10
	net_encrypted = net.get_encrypted()
	print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
print '+----------------+--------+--------+--------+'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752ccc>}
nname: 0
n 0(None)[dev_name, net_name = parameter_s.split()
dev = _get_device_by_name(dev_name)
net = _get_network_by_name(dev, net_name)
print 'Activating ...',
NM.set_active_device(dev, net)
print 'done!'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb774becc>}
nname: 0
n 0(None)[dev = _get_device_by_name(parameter_s)
print 'Activating ...',
NM.set_active_device(dev)
print 'done!'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb774bd2c>}
nname: 0
n 0(None)[dev_name, net_name = parameter_s.split()
dev = _get_device_by_name(dev_name)
net = _get_network_by_name(dev, net_name)
print 'Activating ...',
NM.set_active_device(dev, net)
print 'done!'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb774bd4c>}
nname: 0
n 0(None)[dev_name, net_name, cypher, key, auth_alg = parameter_s.split()
dev = _get_device_by_name(dev_name)
net = _get_network_by_name(dev, net_name)
print 'Activating ...',
NM.set_active_device(dev, net, cypher, key, auth_alg=auth_alg)
print 'done!'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7752f0c>}
nname: 0
n 0(None)[dev_name, net_name, cypher, key, wpa_version, key_mgt = parameter_s.split()
dev = _get_device_by_name(dev_name)
net = _get_network_by_name(dev, net_name)
print 'Activating ...',
NM.set_active_device(dev, net, cypher, key, wpa_version=wpa_version, key_mgt=key_mgt)
print 'done!'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77525cc>}
nname: 0
n 0(None)[print '\nUsage:\n  activate_eth <device>     (wired network)\n  activate_wlan <device> <essid>    (open wireless network)\n  activate_wep <device> <essid> <cypher> <key> <auth_alg>       (wep wireless)\n  activate_wpa <device> <essid> <cypher> <key> <wpa_version> <key_mgt>      (wpa wireless)\n\n# with cypher in:\n    NM_AUTH_TYPE_WPA_PSK_AUTO\n    NM_AUTH_TYPE_NONE\n    NM_AUTH_TYPE_WEP40\n    NM_AUTH_TYPE_WPA_PSK_TKIP\n    NM_AUTH_TYPE_WPA_PSK_CCMP\n    NM_AUTH_TYPE_WEP104\n    NM_AUTH_TYPE_WPA_EAP\n    NM_AUTH_TYPE_LEAP\n\n# with auth_alg in:\n    IW_AUTH_ALG_OPEN_SYSTEM\n    IW_AUTH_ALG_SHARED_KEY\n    IW_AUTH_ALG_LEAP\n\n##### WPA #####\n# with wpa_version in:\n    IW_AUTH_WPA_VERSION_WPA\n    IW_AUTH_WPA_VERSION_WPA2\n\n# with key_mgt in:\n    IW_AUTH_KEY_MGMT_802_1X\n    IW_AUTH_KEY_MGMT_PSK'
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb774b76c>}
nname: 317
n 317(None)[ipshell()
]:
	i: 98(AL), 316()
	o: 

nname: 316
n 316(None)[]:
	i: 239(AF), 312()
	o: 317()

nname: 312
n 312(None)[]:
	i: 255(f), 279()
	o: 316()

nname: 279
n 279(None)[setattr(InteractiveShell, func_name, func)
magic_functions.append(func)
continue
]:
	i: 255(t)
	o: 312()

nname: 255
n 255(func_name.startswith('magic'))[for func_name, func in locals().items():
]:
	i: 239(for)
	o: 279(t), 312(f)

nname: 239
n 239(None)[]:
	i: 98(loop)
	o: 255(for), 316(AF)

nname: 98
n 98(None)[NM = NetworkManager()
ipshell = IPShellEmbed()
def _get_device_by_name(dev_name):
	devs = NM.get_devices()
	d = filter((lambda dev: dev.get_name() == dev_name), devs)
	if d == []:
		raise NameError('No such interface (%s)' % dev_name)
	return d[0]

def _get_network_by_name(dev, essid):
	nets = dev.get_networks()
	n = filter((lambda net: net.get_name() == essid), nets)
	if n == []:
		raise NameError('No such ESSID (%s)' % net_name)
	return n[0]

def magic_list_devices(self, parameter_s=''):
	devs = NM.get_devices()
	print '+--------+----------+--------+---------------+---------------+---------------+'
	print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
	print '+--------+----------+--------+---------------+---------------+---------------+'
	for dev in devs:
		name = dev.get_name()
		ip = dev.get_ip_address()
		type = dev.get_type()
		active = dev.get_link_active()
		print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
	print '+--------+----------+--------+---------------+---------------+---------------+'

def magic_list_networks(self, parameter_s=''):
	args = parameter_s.split()
	dev_name = args[0]
	dev = _get_device_by_name(dev_name)
	networks = dev.get_networks()
	print '+----------------+--------+--------+--------+'
	print '| ESSID          |Strength|  Rate  | Crypt. |'
	print '+----------------+--------+--------+--------+'
	for net in networks:
		net_name = net.get_name()
		net_strength = net.get_strength()
		net_rate = net.get_rate() >> 10
		net_encrypted = net.get_encrypted()
		print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
	print '+----------------+--------+--------+--------+'

def magic_activate_network(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_eth(self, parameter_s=''):
	dev = _get_device_by_name(parameter_s)
	print 'Activating ...',
	NM.set_active_device(dev)
	print 'done!'

def magic_activate_wlan(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_wep(self, parameter_s=''):
	dev_name, net_name, cypher, key, auth_alg = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, auth_alg=auth_alg)
	print 'done!'

def magic_activate_wpa(self, parameter_s=''):
	dev_name, net_name, cypher, key, wpa_version, key_mgt = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, wpa_version=wpa_version, key_mgt=key_mgt)
	print 'done!'

def magic_activate_help(self, parameter_s=''):
	print '\nUsage:\n  activate_eth <device>     (wired network)\n  activate_wlan <device> <essid>    (open wireless network)\n  activate_wep <device> <essid> <cypher> <key> <auth_alg>       (wep wireless)\n  activate_wpa <device> <essid> <cypher> <key> <wpa_version> <key_mgt>      (wpa wireless)\n\n# with cypher in:\n    NM_AUTH_TYPE_WPA_PSK_AUTO\n    NM_AUTH_TYPE_NONE\n    NM_AUTH_TYPE_WEP40\n    NM_AUTH_TYPE_WPA_PSK_TKIP\n    NM_AUTH_TYPE_WPA_PSK_CCMP\n    NM_AUTH_TYPE_WEP104\n    NM_AUTH_TYPE_WPA_EAP\n    NM_AUTH_TYPE_LEAP\n\n# with auth_alg in:\n    IW_AUTH_ALG_OPEN_SYSTEM\n    IW_AUTH_ALG_SHARED_KEY\n    IW_AUTH_ALG_LEAP\n\n##### WPA #####\n# with wpa_version in:\n    IW_AUTH_WPA_VERSION_WPA\n    IW_AUTH_WPA_VERSION_WPA2\n\n# with key_mgt in:\n    IW_AUTH_KEY_MGMT_802_1X\n    IW_AUTH_KEY_MGMT_PSK'

magic_functions = []
]:
	i: 19(), 65(), 96(AE)
	o: 239(loop), 317(AL)

nname: 96
n 96(None)[]:
	i: 55(f)
	o: 98(AE)

nname: 65
n 65(None)[#, e
print 'Failed to import IPython:',
print e
sys.exit(1)
]:
	i: 55(t)
	o: 98()

nname: 55
n 55(<dummy_ex3> EXC_MATCH ImportError)[]:
	i: 0(except)
	o: 65(t), 96(f)

nname: 19
n 19(None)[from IPython.Shell import IPShellEmbed
from IPython.iplib import InteractiveShell
]:
	i: 0(try)
	o: 98()

nname: 0
n 0(None)[from peewee.networkmanager import NetworkManager
]:
	i: 
	o: 19(try), 55(except)

nname: 317
n 317(None)[ipshell()
]:
	i: 55(AL), 239(AF), 255()
	o: 

nname: 255
n 255(None)[for func_name, func in locals().items():
if func_name.startswith('magic'):
	setattr(InteractiveShell, func_name, func)
	magic_functions.append(func)
	continue
]:
	i: 239(for)
	o: 317()

nname: 239
n 239(None)[]:
	i: 55(loop)
	o: 255(for), 317(AF)

nname: 55
n 55(None)[except ImportError, e:
	print 'Failed to import IPython:',
	print e
	sys.exit(1)
NM = NetworkManager()
ipshell = IPShellEmbed()
def _get_device_by_name(dev_name):
	devs = NM.get_devices()
	d = filter((lambda dev: dev.get_name() == dev_name), devs)
	if d == []:
		raise NameError('No such interface (%s)' % dev_name)
	return d[0]

def _get_network_by_name(dev, essid):
	nets = dev.get_networks()
	n = filter((lambda net: net.get_name() == essid), nets)
	if n == []:
		raise NameError('No such ESSID (%s)' % net_name)
	return n[0]

def magic_list_devices(self, parameter_s=''):
	devs = NM.get_devices()
	print '+--------+----------+--------+---------------+---------------+---------------+'
	print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
	print '+--------+----------+--------+---------------+---------------+---------------+'
	for dev in devs:
		name = dev.get_name()
		ip = dev.get_ip_address()
		type = dev.get_type()
		active = dev.get_link_active()
		print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
	print '+--------+----------+--------+---------------+---------------+---------------+'

def magic_list_networks(self, parameter_s=''):
	args = parameter_s.split()
	dev_name = args[0]
	dev = _get_device_by_name(dev_name)
	networks = dev.get_networks()
	print '+----------------+--------+--------+--------+'
	print '| ESSID          |Strength|  Rate  | Crypt. |'
	print '+----------------+--------+--------+--------+'
	for net in networks:
		net_name = net.get_name()
		net_strength = net.get_strength()
		net_rate = net.get_rate() >> 10
		net_encrypted = net.get_encrypted()
		print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
	print '+----------------+--------+--------+--------+'

def magic_activate_network(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_eth(self, parameter_s=''):
	dev = _get_device_by_name(parameter_s)
	print 'Activating ...',
	NM.set_active_device(dev)
	print 'done!'

def magic_activate_wlan(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_wep(self, parameter_s=''):
	dev_name, net_name, cypher, key, auth_alg = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, auth_alg=auth_alg)
	print 'done!'

def magic_activate_wpa(self, parameter_s=''):
	dev_name, net_name, cypher, key, wpa_version, key_mgt = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, wpa_version=wpa_version, key_mgt=key_mgt)
	print 'done!'

def magic_activate_help(self, parameter_s=''):
	print '\nUsage:\n  activate_eth <device>     (wired network)\n  activate_wlan <device> <essid>    (open wireless network)\n  activate_wep <device> <essid> <cypher> <key> <auth_alg>       (wep wireless)\n  activate_wpa <device> <essid> <cypher> <key> <wpa_version> <key_mgt>      (wpa wireless)\n\n# with cypher in:\n    NM_AUTH_TYPE_WPA_PSK_AUTO\n    NM_AUTH_TYPE_NONE\n    NM_AUTH_TYPE_WEP40\n    NM_AUTH_TYPE_WPA_PSK_TKIP\n    NM_AUTH_TYPE_WPA_PSK_CCMP\n    NM_AUTH_TYPE_WEP104\n    NM_AUTH_TYPE_WPA_EAP\n    NM_AUTH_TYPE_LEAP\n\n# with auth_alg in:\n    IW_AUTH_ALG_OPEN_SYSTEM\n    IW_AUTH_ALG_SHARED_KEY\n    IW_AUTH_ALG_LEAP\n\n##### WPA #####\n# with wpa_version in:\n    IW_AUTH_WPA_VERSION_WPA\n    IW_AUTH_WPA_VERSION_WPA2\n\n# with key_mgt in:\n    IW_AUTH_KEY_MGMT_802_1X\n    IW_AUTH_KEY_MGMT_PSK'

magic_functions = []
]:
	i: 0()
	o: 239(loop), 317(AL)

nname: 0
n 0(None)[from peewee.networkmanager import NetworkManager
try:
	from IPython.Shell import IPShellEmbed
	from IPython.iplib import InteractiveShell
]:
	i: 
	o: 55()

nname: 317
n 317(None)[ipshell()
]:
	i: 0(AL), 239(AF), 255()
	o: 

nname: 255
n 255(None)[for func_name, func in locals().items():
if func_name.startswith('magic'):
	setattr(InteractiveShell, func_name, func)
	magic_functions.append(func)
	continue
]:
	i: 239(for)
	o: 317()

nname: 239
n 239(None)[]:
	i: 0(loop)
	o: 255(for), 317(AF)

nname: 0
n 0(None)[from peewee.networkmanager import NetworkManager
try:
	from IPython.Shell import IPShellEmbed
	from IPython.iplib import InteractiveShell
except ImportError, e:
	print 'Failed to import IPython:',
	print e
	sys.exit(1)
NM = NetworkManager()
ipshell = IPShellEmbed()
def _get_device_by_name(dev_name):
	devs = NM.get_devices()
	d = filter((lambda dev: dev.get_name() == dev_name), devs)
	if d == []:
		raise NameError('No such interface (%s)' % dev_name)
	return d[0]

def _get_network_by_name(dev, essid):
	nets = dev.get_networks()
	n = filter((lambda net: net.get_name() == essid), nets)
	if n == []:
		raise NameError('No such ESSID (%s)' % net_name)
	return n[0]

def magic_list_devices(self, parameter_s=''):
	devs = NM.get_devices()
	print '+--------+----------+--------+---------------+---------------+---------------+'
	print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
	print '+--------+----------+--------+---------------+---------------+---------------+'
	for dev in devs:
		name = dev.get_name()
		ip = dev.get_ip_address()
		type = dev.get_type()
		active = dev.get_link_active()
		print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
	print '+--------+----------+--------+---------------+---------------+---------------+'

def magic_list_networks(self, parameter_s=''):
	args = parameter_s.split()
	dev_name = args[0]
	dev = _get_device_by_name(dev_name)
	networks = dev.get_networks()
	print '+----------------+--------+--------+--------+'
	print '| ESSID          |Strength|  Rate  | Crypt. |'
	print '+----------------+--------+--------+--------+'
	for net in networks:
		net_name = net.get_name()
		net_strength = net.get_strength()
		net_rate = net.get_rate() >> 10
		net_encrypted = net.get_encrypted()
		print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
	print '+----------------+--------+--------+--------+'

def magic_activate_network(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_eth(self, parameter_s=''):
	dev = _get_device_by_name(parameter_s)
	print 'Activating ...',
	NM.set_active_device(dev)
	print 'done!'

def magic_activate_wlan(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_wep(self, parameter_s=''):
	dev_name, net_name, cypher, key, auth_alg = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, auth_alg=auth_alg)
	print 'done!'

def magic_activate_wpa(self, parameter_s=''):
	dev_name, net_name, cypher, key, wpa_version, key_mgt = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, wpa_version=wpa_version, key_mgt=key_mgt)
	print 'done!'

def magic_activate_help(self, parameter_s=''):
	print '\nUsage:\n  activate_eth <device>     (wired network)\n  activate_wlan <device> <essid>    (open wireless network)\n  activate_wep <device> <essid> <cypher> <key> <auth_alg>       (wep wireless)\n  activate_wpa <device> <essid> <cypher> <key> <wpa_version> <key_mgt>      (wpa wireless)\n\n# with cypher in:\n    NM_AUTH_TYPE_WPA_PSK_AUTO\n    NM_AUTH_TYPE_NONE\n    NM_AUTH_TYPE_WEP40\n    NM_AUTH_TYPE_WPA_PSK_TKIP\n    NM_AUTH_TYPE_WPA_PSK_CCMP\n    NM_AUTH_TYPE_WEP104\n    NM_AUTH_TYPE_WPA_EAP\n    NM_AUTH_TYPE_LEAP\n\n# with auth_alg in:\n    IW_AUTH_ALG_OPEN_SYSTEM\n    IW_AUTH_ALG_SHARED_KEY\n    IW_AUTH_ALG_LEAP\n\n##### WPA #####\n# with wpa_version in:\n    IW_AUTH_WPA_VERSION_WPA\n    IW_AUTH_WPA_VERSION_WPA2\n\n# with key_mgt in:\n    IW_AUTH_KEY_MGMT_802_1X\n    IW_AUTH_KEY_MGMT_PSK'

magic_functions = []
]:
	i: 
	o: 239(loop), 317(AL)

self.nodes: {0: <unpyclib.structure.node instance at 0xb774bf0c>, 239: <unpyclib.structure.node instance at 0xb7743bcc>, 317: <unpyclib.structure.node instance at 0xb7743e4c>, 255: <unpyclib.structure.node instance at 0xb774b2ac>}
from peewee.networkmanager import NetworkManager
try:
	from IPython.Shell import IPShellEmbed
	from IPython.iplib import InteractiveShell
except ImportError, e:
	print 'Failed to import IPython:',
	print e
	sys.exit(1)
NM = NetworkManager()
ipshell = IPShellEmbed()
def _get_device_by_name(dev_name):
	devs = NM.get_devices()
	d = filter((lambda dev: dev.get_name() == dev_name), devs)
	if d == []:
		raise NameError('No such interface (%s)' % dev_name)
	return d[0]

def _get_network_by_name(dev, essid):
	nets = dev.get_networks()
	n = filter((lambda net: net.get_name() == essid), nets)
	if n == []:
		raise NameError('No such ESSID (%s)' % net_name)
	return n[0]

def magic_list_devices(self, parameter_s=''):
	devs = NM.get_devices()
	print '+--------+----------+--------+---------------+---------------+---------------+'
	print '| Device |   Type   | Active |  IP Address   |    Netmask    |   Broadcast   |'
	print '+--------+----------+--------+---------------+---------------+---------------+'
	for dev in devs:
		name = dev.get_name()
		ip = dev.get_ip_address()
		type = dev.get_type()
		active = dev.get_link_active()
		print '|%-8.8s|%-10.10s|%-8.8s|%-15.15s|%-15.15s|%-15.15s|' % (name, type, active, ip, 'Unkonwn', 'Unknown')
	print '+--------+----------+--------+---------------+---------------+---------------+'

def magic_list_networks(self, parameter_s=''):
	args = parameter_s.split()
	dev_name = args[0]
	dev = _get_device_by_name(dev_name)
	networks = dev.get_networks()
	print '+----------------+--------+--------+--------+'
	print '| ESSID          |Strength|  Rate  | Crypt. |'
	print '+----------------+--------+--------+--------+'
	for net in networks:
		net_name = net.get_name()
		net_strength = net.get_strength()
		net_rate = net.get_rate() >> 10
		net_encrypted = net.get_encrypted()
		print '|%-16.16s|%-8.8s|%-8.8s|%-8.8s|' % (net_name, net_strength, net_rate, net_encrypted)
	print '+----------------+--------+--------+--------+'

def magic_activate_network(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_eth(self, parameter_s=''):
	dev = _get_device_by_name(parameter_s)
	print 'Activating ...',
	NM.set_active_device(dev)
	print 'done!'

def magic_activate_wlan(self, parameter_s=''):
	dev_name, net_name = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net)
	print 'done!'

def magic_activate_wep(self, parameter_s=''):
	dev_name, net_name, cypher, key, auth_alg = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, auth_alg=auth_alg)
	print 'done!'

def magic_activate_wpa(self, parameter_s=''):
	dev_name, net_name, cypher, key, wpa_version, key_mgt = parameter_s.split()
	dev = _get_device_by_name(dev_name)
	net = _get_network_by_name(dev, net_name)
	print 'Activating ...',
	NM.set_active_device(dev, net, cypher, key, wpa_version=wpa_version, key_mgt=key_mgt)
	print 'done!'

def magic_activate_help(self, parameter_s=''):
	print '\nUsage:\n  activate_eth <device>     (wired network)\n  activate_wlan <device> <essid>    (open wireless network)\n  activate_wep <device> <essid> <cypher> <key> <auth_alg>       (wep wireless)\n  activate_wpa <device> <essid> <cypher> <key> <wpa_version> <key_mgt>      (wpa wireless)\n\n# with cypher in:\n    NM_AUTH_TYPE_WPA_PSK_AUTO\n    NM_AUTH_TYPE_NONE\n    NM_AUTH_TYPE_WEP40\n    NM_AUTH_TYPE_WPA_PSK_TKIP\n    NM_AUTH_TYPE_WPA_PSK_CCMP\n    NM_AUTH_TYPE_WEP104\n    NM_AUTH_TYPE_WPA_EAP\n    NM_AUTH_TYPE_LEAP\n\n# with auth_alg in:\n    IW_AUTH_ALG_OPEN_SYSTEM\n    IW_AUTH_ALG_SHARED_KEY\n    IW_AUTH_ALG_LEAP\n\n##### WPA #####\n# with wpa_version in:\n    IW_AUTH_WPA_VERSION_WPA\n    IW_AUTH_WPA_VERSION_WPA2\n\n# with key_mgt in:\n    IW_AUTH_KEY_MGMT_802_1X\n    IW_AUTH_KEY_MGMT_PSK'

magic_functions = []
